package com.zzyl.nursing.service.impl;

import cn.hutool.json.JSONUtil;
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.zzyl.nursing.service.IQianFanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class QianFanServiceImpl implements IQianFanService {


    @Value("${qianfan.accessKey}")
    private  String accessKey;
    @Value("${qianfan.secretKey}")
    private  String secretKey;
    @Value("${qianfan.model}")
    private  String model;
    @Override
    public String chat(String prompt) {
        log.info("开始与大模型对话");
        Qianfan qianfan = new Qianfan(accessKey,secretKey);
        ChatResponse response = qianfan.chatCompletion()
                .addUserMessage(prompt)
                .model(model)
                .responseFormat("json_object")
                .execute();
        log.info("大模型返回数据：{}", JSONUtil.toJsonStr(response));
        return response.getResult();
    }
}
